
#include "threadpool.h"
#include <iostream>
#include <unistd.h>
#include <mutex>
#include <thread>
std::mutex globalMutex;
int32_t count=0;

void printCount()
{
    sleep(1);
    std::lock_guard<std::mutex> lock(globalMutex);
    std::cout<<"threadID:"<<std::this_thread::get_id()<<std::endl;
    std::cout<<"count="<<count<<std::endl;
    count++;
}

void printSum()
{
    for(size_t i=0;i<1000000;i++){
        std::lock_guard<std::mutex> lock(globalMutex);
        count++;
    }
}

int main()
{
    daniel::ThreadPool::ptr threadPool(new daniel::ThreadPool(4,8));
    for(int i=0;i<1000;i++){
        threadPool->addTask(printSum);
    }
    threadPool->stop();
    std::cout<<"sum="<<count<<std::endl;
    return 0;
}